package com.privacy.accountmgr.views.numberpasswordview

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.text.TextUtils
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.privacy.accountmgr.utils.ScreenUtils


class NumberKeyboardAdapter(internal var mContext: Context) : BaseAdapter() {
    private val data = arrayOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "", "0", "DEL")

    override fun getCount(): Int {
        return data.size
    }

    override fun getItem(position: Int): String {
        return data[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val tvNumber: TextView
        if (convertView == null) {
            tvNumber = TextView(mContext)
            tvNumber.textSize = 28f
            tvNumber.gravity = Gravity.CENTER
            tvNumber.setTextColor(Color.WHITE)
            val layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ScreenUtils.dp2px(80f).toInt())
            tvNumber.layoutParams = layoutParams
        } else {
            tvNumber = convertView as TextView
        }
        
        tvNumber.isEnabled = !TextUtils.isEmpty(getItem(position))
        tvNumber.text = getItem(position)
        return tvNumber
    }

    private fun getBackground() {
        val gradientDrawableMiddle = GradientDrawable()
        gradientDrawableMiddle.shape = GradientDrawable.OVAL
        gradientDrawableMiddle.setColor(Color.parseColor("#ffa025"))
        gradientDrawableMiddle.setSize(50, 50)
    }

    companion object {
        val NUMBERS = "123456789"
        val KEY_CLEAR = "清空"
        val KEY_ZERO = "0"
        val KEY_DELETE = "删除"
    }
}
